package com.suixun.service.information.impl;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.suixun.dao.ZxArticleTagMapper;
import com.suixun.dao.ZxTagMapper;
import com.suixun.entity.ZxTag;
import com.suixun.entity.ZxTagExample;
import com.suixun.service.information.ZxTagService;
@Service
public class ZxTagServiceImpl implements ZxTagService{
    
    @Resource
    private ZxTagMapper zxTagMapper;
    @Resource
    private ZxArticleTagMapper zxArticleTagMapper;
    @Resource
    private SqlSessionTemplate sqlSessionTemplate;

    @Override
    public PageInfo<ZxTag> listTag(Integer page, Integer size) {

        PageHelper.startPage(page, size);
        ZxTagExample example = new ZxTagExample();
        example.setOrderByClause(" p_index asc ");
        List<ZxTag> list = zxTagMapper.selectByExample(example);
        
        return new PageInfo<ZxTag>(list);
    }

    @Override
    public List<ZxTag> listTag() {
        
        ZxTagExample example = new ZxTagExample();
        example.setOrderByClause(" p_index asc ");
        return zxTagMapper.selectByExample(example);
    }

    @Override
    public ZxTag getTag(Integer tagId) {
        
        return zxTagMapper.selectByPrimaryKey(tagId);
    }

    @Override
    public void addTag(ZxTag tag) {
       
        zxTagMapper.insert(tag);
    }

    @Override
    public void updateTag(ZxTag tag) {
        
        zxTagMapper.updateByPrimaryKey(tag);
    }

    @Override
    public void del(Integer tagId) {
        
        ZxTag tag = zxTagMapper.selectByPrimaryKey(tagId);
        if(tag != null){
            tag.setDel((short)1);
            zxTagMapper.updateByPrimaryKey(tag);
        }
    }

	@Override
	public List<ZxTag> listArticleTag(Integer articleId) {
		
		return sqlSessionTemplate.selectList("ZxTagExtendSql.listTagByArticleId", articleId);
	}

}
